//
//  LBNiuwaDetailCell.m
//  V-Learn
//
//  Created by Apple on 2019/1/2.
//  Copyright © 2019 yxk. All rights reserved.
//

#import "VKRecordNiuWaCell.h"
#import "VKRecordInfoModel.h"
@implementation VKRecordNiuWaCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])
    {
        [self setupUI];
    }
    return self;
}
+ (instancetype)cellWithTableView:(UITableView *)tableView
{
    static NSString *identifferCell = @"VKRecordNiuWaCell";
    VKRecordNiuWaCell *cell = [tableView dequeueReusableCellWithIdentifier:identifferCell];
    if (!cell) {
        cell = [[VKRecordNiuWaCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifferCell];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        
    }
    return cell;
}
-(void)setModel:(WKHotmenModel *)model{
    _model = model;
    if ([model.isVip integerValue]==1) {
        _vipImageV.hidden = NO;
    }else{
        _vipImageV.hidden = YES;
    }
    [self.icon sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",Public_URL,model.headImg]] placeholderImage:[UIImage imageNamed:@"logo"]];
    self.nickLab.text = model.username;
    NSString *timeStr = [model.clockDate substringToIndex:10];
    self.timeLab.text = timeStr;
    
    self.titleLab.text = model.clockTitle;
    //主题课程第四级
    self.detailLab.text = model.clockOrtherTitle;
    
    if ([model.isPrase integerValue] == 1) {
        [self.zanButton setImage:LBImage(@"wk_Fabulous") forState:UIControlStateNormal];
    }else{
        [self.zanButton setImage:LBImage(@"wk_unFabulous") forState:UIControlStateNormal];
    }

    [self.zanButton setTitle:model.praiseNum forState:UIControlStateNormal];

    if (model.clockInfoVOList.count>0) {
        WKHotclockInfoVOListModel *videoModel = model.clockInfoVOList[0];
        NSString *videoCover;
        if (videoModel.videoCover) {
         videoCover   = [NSString stringWithFormat:@"%@%@",Public_URL,videoModel.videoCover];
        }else{
            videoCover = [NSString stringWithFormat:@"%@%@",Public_URL,videoModel.infoFile];
        }
        
        [self.bigIcon sd_setImageWithURL:[NSURL URLWithString:videoCover] placeholderImage:[UIImage imageNamed:@"wk_list_bgimg"]];
        
        if (videoModel.infoContent.length==0||videoModel.infoContent==nil) {
            self.descLab.text = @"";
        }else{
            self.descLab.text = videoModel.infoContent;
        }

        
    }else{
        [self.bigIcon sd_setImageWithURL:@"" placeholderImage:[UIImage imageNamed:@"kaifeng"]];
    }
    
    if ([model.fileType isEqualToString:@"1"]) {
        self.playIcon.hidden = NO;
    }else{
        self.playIcon.hidden = YES;
    }
}
- (void)setupUI{
    
    UIView *bgView = [UIView new];
    bgView.frame = CGRectMake(0, 0, ScreenW, 80);
    [self.contentView addSubview:bgView];
    bgView.backgroundColor = [UIColor whiteColor];
    //    [bgView makeConstraints:^(MASConstraintMaker *make) {
    //        make.left.top.right.mas_equalTo(0);
    //        make.height.mas_equalTo(80);
    //    }];
    
    
    self.icon = [[UIImageView alloc] init];
    self.icon.image = [UIImage imageNamed:@"wk_list_bgimg"];
    self.icon.layer.cornerRadius = 22.5;
    self.icon.layer.masksToBounds = YES;
    
    [bgView addSubview:self.icon];
    [self.icon makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.centerY.mas_equalTo(bgView);
        make.size.mas_equalTo(CGSizeMake(45, 45));
    }];
    
    UIImageView *vipImageV = [[UIImageView alloc]init];
    vipImageV.image = [UIImage imageNamed:@"wk_vip"];
    vipImageV.contentMode = UIViewContentModeScaleAspectFill;
    vipImageV.clipsToBounds = YES;
    _vipImageV = vipImageV;
    [bgView addSubview:vipImageV];
    vipImageV.userInteractionEnabled = NO;
    vipImageV.layer.cornerRadius = 7.5;
    vipImageV.layer.masksToBounds = YES;
    [vipImageV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self.icon).offset(0);
        make.size.mas_equalTo(CGSizeMake(15, 15));
        make.bottom.mas_equalTo(self.icon);
    }];
    
    self.nickLab = [UILabel labelWithText:@"何以繁华笙歌落" andTextColor:rgb(51,51,51) andName:nil andFontSize:15];
    [bgView addSubview:self.nickLab];
    [self.nickLab makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.icon.mas_right).mas_equalTo(10);
        make.top.mas_equalTo(self.icon.mas_top);
        make.right.mas_equalTo(-40);
    }];
    
    
    self.timeLab = [UILabel labelWithText:@"18:09" andTextColor:rgb(102,102,102) andName:nil andFontSize:12];
    [bgView addSubview:self.timeLab];
    [self.timeLab makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.icon.mas_right).mas_equalTo(10);
        make.top.mas_equalTo(self.nickLab.mas_bottom).mas_equalTo(10);
        make.right.mas_equalTo(-40);
    }];
    
    self.followButton = [[UIButton alloc] init];
    [bgView addSubview:self.followButton];
    [self.followButton setTitle:@"" forState:UIControlStateNormal];
    self.followButton.layer.cornerRadius = 13;
    self.followButton.layer.masksToBounds = YES;
    [self.followButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    
    self.followButton.titleLabel.font = LBFont(14);
    [self.followButton makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-15);
        make.centerY.mas_equalTo(bgView);
        make.size.mas_equalTo(CGSizeMake(70, 26));
    }];
//    self.titleLab = [UILabel labelWithText:@"万思乐学 小西妈双语工程 20180725008  耿思悦201503 北京 28次 20181026" andTextColor:rgb(51,51,51) andName:nil andFontSize:14];
    self.titleLab = [[UILabel alloc]init];
    self.titleLab.text = @"Lucia家，不温不火的状态，从从容容地按自己的进度启蒙，我喜欢这样首先把自己的事做好，能有持久战斗力...";
    self.titleLab.textColor = rgb(51,51,51);
    self.titleLab.backgroundColor = [UIColor cyanColor];
    self.titleLab.numberOfLines = 2;
    self.titleLab.font = [UIFont systemFontOfSize:14];
    [self.contentView addSubview:self.titleLab];
    self.titleLab.backgroundColor = [UIColor whiteColor];
    [self.titleLab makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.top.mas_equalTo(bgView.mas_bottom).mas_equalTo(-8);
        make.right.mas_equalTo(-15);
    }];
    self.detailLab = [UILabel labelWithText:@"主题课程1级 第一课时" andTextColor:rgb(102,102,102) andName:nil andFontSize:12];
    
    [self.contentView addSubview:self.detailLab];
    [self.detailLab makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.top.mas_equalTo(self.titleLab.mas_bottom).mas_equalTo(10);
        make.right.mas_equalTo(-15);
    }];
    
    self.bigIcon = [[UIImageView alloc] init];
    self.bigIcon.image = [UIImage imageNamed:@"wk_list_bgimg"];
    self.bigIcon.clipsToBounds = YES;
    self.bigIcon.contentMode = UIViewContentModeScaleAspectFill;
    [self.contentView addSubview:self.bigIcon];
    [self.bigIcon makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.right.mas_equalTo(-15);
        make.top.mas_equalTo(self.detailLab.mas_bottom).mas_equalTo(10);
        make.height.mas_equalTo(190);
    }];
    
    self.playIcon = [[UIImageView alloc] init];
    self.playIcon.image = [UIImage imageNamed:@"vkplay"];
    self.playIcon.layer.cornerRadius = 20;
    self.playIcon.layer.masksToBounds = YES;
    
    [self.bigIcon addSubview:self.playIcon];
    [self.playIcon makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.bigIcon);
        make.centerX.mas_equalTo(self.bigIcon);
        make.size.mas_equalTo(CGSizeMake(40, 40));
    }];
    
    //底部描述label
    self.descLab = [[UILabel alloc]init];
    self.descLab.text = @"Lucia家，不温不火的状态，从从容容地按自己的进度启蒙，我喜欢这样首先把自己的事做好，能有持久战斗力...";
    self.descLab.textColor = rgb(102,102,102);
    self.descLab.font = [UIFont systemFontOfSize:14];
    [self.contentView addSubview:self.descLab];
    self.descLab.numberOfLines = 2;
    [self.descLab makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.top.mas_equalTo(self.bigIcon.mas_bottom).mas_equalTo(10);
        make.right.mas_equalTo(-15);
    }];
    
    
    UIView *bottomView = [UIView new];
    [self.contentView addSubview:bottomView];
    bottomView.backgroundColor = [UIColor whiteColor];
    [bottomView makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(0);
        make.top.mas_equalTo(self.descLab.mas_bottom).offset(5);
        make.height.equalTo(@35);
    }];
    
    self.zanButton = [[UIButton alloc] init];
    [bottomView addSubview:self.zanButton];
    [self.zanButton setTitle:@"0" forState:UIControlStateNormal];
    [self.zanButton setTitleColor:rgb(102,102,102) forState:UIControlStateNormal];
    [self.zanButton setImage:LBImage(@"wk_Fabulous") forState:UIControlStateSelected];
    [self.zanButton setImage:LBImage(@"wk_unFabulous") forState:UIControlStateNormal];
    
    self.zanButton.titleLabel.font = LBFont(12*ScaleX);
    [self.zanButton makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-10*ScaleX);
        make.centerY.mas_equalTo(bottomView);
        make.size.mas_equalTo(CGSizeMake(60*ScaleX, 24*ScaleX));
    }];
    
    [self.zanButton setImageEdgeInsets:UIEdgeInsetsMake(0, -3*ScaleX, 0, 0)];
    [self.zanButton setTitleEdgeInsets:UIEdgeInsetsMake(0, 3*ScaleX, 0, 0)];
    
    UIView *downView = [UIView new];
    [self.contentView addSubview:downView];
    downView.backgroundColor = [UIColor cz_colorWithRed:242 green:242 blue:242];
    [downView makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.left.right.mas_equalTo(0);
        make.top.mas_equalTo(bottomView.mas_bottom).offset(2);
        make.height.equalTo(@10);
    }];
    
}

@end
